<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    #drawing {  
      border: 10px solid aquamarine;
      margin: 100px auto 0;
      display: block;
    }
  </style>
</head>
<body>
  <canvas id="drawing" width="300" height="300"></canvas>
  
  <script>
    let drawing = document.getElementById("drawing");
    // 确保浏览器支持<canvas>
    if (drawing.getContext) {
      let context = drawing.getContext("2d");
      // 创建路径
      context.beginPath();
      // 绘制外圆
      context.arc(100, 100, 99, 0, 2 * Math.PI, false);
      // 绘制内圆
      context.moveTo(194, 100);
      context.arc(100, 100, 94, 0, 2 * Math.PI, false);
      // 绘制分针
      context.moveTo(100, 100);
      context.lineTo(100, 15);
      // 绘制时针
      context.moveTo(100, 100);
      context.lineTo(35, 100);
      // 描画路径
      context.stroke();

      // 使用 toDataURL 可以导出 canvas 上的图像
      const imgUrl = drawing.toDataURL('image/png')

      // 显示图片
      const img = document.createElement('img')
      img.src = imgUrl
      document.body.appendChild(img)
    }
  </script>
</body>
</html>